package requests

import (
	"github.com/sonhineboy/meituanMediaSdk/apis"
)

type ProductRequest struct {
	Category   int     `json:"category" form:"category" binding:"required,oneof=1 2"`
	BizLine    int     `json:"bizLine" form:"bizLine" binding:"required,oneof=1 2 3 4 5 6"`
	TopiId     *int    `form:"topiId" json:"topi_id" binding:"omitempty,oneof=1 2 3 4"`
	SearchText *string `form:"searchText" json:"search_text" binding:"omitempty"`
	PageNo     int     `form:"pageNo" json:"page_no" binding:"omitempty,min=0"`
	SearchId   string  `form:"searchId" json:"search_id" binding:"omitempty"`
	CityId     string  `form:"cityId" json:"city_id" binding:"omitempty"`
}

func (p *ProductRequest) ToRequestBody() *apis.RequestBody {
	reqBody := apis.NewRequestBody(apis.WithBizLine(p.BizLine), apis.WithPlatform(p.Category), apis.WithPageSize(8))

	if p.SearchText != nil {
		reqBody.SearchText = p.SearchText
	}
	if p.TopiId != nil && p.SearchText == nil {
		reqBody.ListTopiId = p.TopiId
	}

	if p.CityId != "" {
		reqBody.CityId = p.CityId
	}

	if len(p.SearchId) > 0 {
		reqBody.SearchId = p.SearchId
	}

	if p.PageNo != 0 {
		reqBody.PageNo = &p.PageNo
	}

	return reqBody
}
